<?php
use yii\helpers\Html;
use yii\grid\GridView;
use app\models\User;

/* @var $this MessageController */
/* @var $dataProvider CActiveDataProvider */
?>
<blockquote class="meta">
<h2><?php echo Yii::t('Message','Inbox') ?></h2>
</blockquote>
<br>
<form method="post">
    <p style="text-align:left">
        <input type="submit" class="btn btn-default" name="submitDelete" value="<?php echo Yii::t('Message', 'Delete')?>" >
        <input type="submit" class="btn btn-default" name="submitRead" value="<?php echo Yii::t('Message', 'Read')?>" >
        <input type="submit" class="btn btn-default" name="submitUnread" value="<?php echo Yii::t('Message', 'Unread')?>" >
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
           // ['class' => 'yii\grid\SerialColumn'],
            [
                'class' => 'yii\grid\CheckboxColumn',
                'headerOptions' => array('width'=>'33px','style'=>'text-align:center'),
                'checkboxOptions' => array('name' => 'select[]'),
                'options'=>array(
                    'style'=>'text-align:center',
                ),
            ],
            [
                'attribute'=>'message_id',
                'options'=>array(
                    'width'=>'60',
                    'style'=>'text-align:center',
                ),
            ],
            [
                'attribute'=>'isRead',
                'value'=>function ($model, $key, $index, $column){
                    return $model->isReadText();
                    },
                        'filter'=>$searchModel->getIsReadOptions(),
                        'options'=>array(
                    'width'=>'120',
                    'style'=>'text-align:center',
                ),
            ],
            [
                'attribute'=>'title',
                'format'=>'raw',
                'value'=>function ($model, $key, $index, $column){
                    return Html::a($model->title, yii::$app->urlManager->createUrl(['message/view','id'=>$model->message_id]));
                    },
            ],
            [
                'attribute'=>'sender_id',
                'value'=>function ($model, $key, $index, $column){
                    return $model->sender->user_name;
                    },
                    'options'=>array(
                    'width'=>'120',
                    'style'=>'text-align:center',
                ),
            ],
            [
                'attribute'=>'create_date',
                    'options'=>array(
                    'width'=>'200',
                    'style'=>'text-align:center',
                ),
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'template'=>'{view} {delete}',
            ],
        ],
    ]); ?>

</form>
<?php /*$form=$this->beginWidget('CActiveForm', array(
	'id'=>'message-form',
    'enableAjaxValidation'=>false,
));?>


<?php/* $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'message-grid',
	'dataProvider'=>$model->search('inbox'),
	'filter'=>$model,
	'columns'=>array(
        //	'message_id',
        array(
            'selectableRows' => 2,
            'class' => 'CCheckBoxColumn',
            'headerHtmlOptions' => array('width'=>'33px','style'=>'text-align:center'),
            'checkBoxHtmlOptions' => array('name' => 'select[]'),
            'htmlOptions'=>array(
                'style'=>'text-align:center',
            ),
        ),
        array(
            'name'=>'isRead',
            'type'=>'raw',
            'value'=>'$data->isRead() == 0 ? CHtml::link(CHtml::image(Yii::app()->baseUrl."/images/unread.png"),array("view","id"=>"$data->message_id")) : ""',
            'filter'=>$model->getIsReadOptions(),
            'htmlOptions'=>array(
                'width'=>'71',
                'style'=>'text-align:center',
            ),
        ),
       array(
            'name'=>'title',
            'type'=>'raw',
            'value'=>'CHtml::link($data->title,array("view","id"=>$data->message_id))',
        ),
        array(
            'name'=>'sender_id',
            'type'=>'raw',
            'value'=>'CHtml::link($data->sender->user_name,array("user/profile","name"=>$data->sender->user_name))',
            'htmlOptions'=>array(
                'width'=>'100',
            ),
        ),

//	'receiver_id',
	//	'title',
		'create_date',
		/*
		'read',
		'status',
		*/
/*
		array(
            'class'=>'CButtonColumn',
            'header'=>Yii::t('message/views', 'Actions'),
			'template'=>'{view} {delete}',
		),
	),
)); ?>
<?php //一个待解决的问题：当把CGridview放在form表单里时将无法使用过滤器进行搜索?>
<?php $this->endWidget(); ?>
